<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="full-screen" content="yes">
    <meta name="x5-fullscreen" content="true">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../../css/base.css">
    <link rel="stylesheet" href="../../css/icon-font.css"/><!--图标-->
    <link rel="stylesheet" href="../../css/info-list.css"/><!--资讯列表-->
    <link rel="stylesheet" href="../../css/report-list.css"/><!--研报列表-->
    <link rel="stylesheet" href="../../plugin/mescroll/css/mescroll.min.css">

    <title>搜索</title>
    <style>

        em {
            color: #2C68FF;
            font-style: initial;
        }

        .index-search-wrap {
            padding: 0 .32rem;
            background: rgba(255, 255, 255, 1);
        }

        .index-search-box {
            margin-bottom: .12rem;
            margin-top: .12rem;
        }

        .index-search-img {
            width: 7.5rem;
            height: 3rem;
        }

        .index-search-img img {
            width: 100%;
            height: 100%;
        }

        .index-search-search {
            height: .64rem;
            width: 6.08rem;
            border-radius: .08rem;
            background: rgba(245, 245, 245, 1);
        }

        .index-search-icon {
            margin-left: .24rem;
            color: rgba(159, 159, 159, 1);
        }

        .index-search-sc {
            color: rgba(159, 159, 159, 1);
            height: .64rem;
            width: .92rem;
            line-height: .64rem;
            margin: auto;
            text-align: center;
        }


        .index-search-search i {
            margin-right: .26rem;
        }

        .index-search-search input {
            margin-left: .14rem;
            line-height: .6rem;
        }

        input[type=search]::-webkit-search-cancel-button {
            -webkit-appearance: none;
        }

        .index-search-cancle {
            color: rgba(44, 104, 255, 1);
        }



        .featured-video-item {
            padding: 16px 0;
            border-bottom: 1px solid #f6f6f6;
        }

        .featured-video-item-img-wrap {
            position: relative;
            width: 2.8rem;
            height: 1.6rem;
        }

        .featured-video-item-img {
            width: 2.8rem;
            height: 1.6rem;
        }

        .featured-video-item-img img {
            width: 100%;
            height: 100%;
            border-radius: 4px;
        }

        .featured-video-item-time {
            position: absolute;
            top: 1.2rem;
            right: 0.1rem;
        }

        .featured-video-item-time div {
            background-color: rgba(0, 0, 0, 0.25);
            color: rgba(255, 255, 255, 0.8);
            padding: 1px 4px;
        }

        .featured-video-item-content {
            height: 1.6rem;
        }

        .featured-video-item-bottom {
            color: rgba(34, 34, 34, 0.45)
        }

        .featured-video-item-icon {
            color: #B9B9B9;
        }
        .search-voide-list {
            padding: 0 .32rem;
        }


    </style>
</head>
<body>

<div class="flex-column h-100-p ff400">

    <!--状态栏-->
    <div class="placeholder-top">
        <!--状态栏-->
        <div class="bg-main status-bar pos-f"></div>
        <!--导航栏-->
        <div class="bg-main nav-bar pos-f flex-row justify-content-between c-white align-items-center">
            <div class="left-bar" onclick="clickBack()">
                <span class="iconfont iconfanhui1 fs16"></span>
            </div>
            <div class="center-bar fs16 ff500 line1"></div>
            <div class="right-bar">
            </div>
        </div>
    </div>

    <div id="mescroll" class="flex-1 mescroll bg-white">
        <div class="search-voide-list"></div>
    </div>

</div>

</body>
<!--这四个文件的引入必须按照顺序-->
<script src="../../js/dict.js"></script>
<script src="../../js/jquery-3.4.1.min.js"></script>
<script src="../../js/checkJsBridge.js"></script>
<script src="../../js/utils.js"></script>
<script src="../../js/api.js"></script>
<!--这四个文件的引入必须按照顺序-->
<script src="../../js/date.js"></script>
<script src="../../js/icon-font.js"></script><!--用于彩色字体图标-->
<script src="../../js/template.js"></script>

<script src="../../plugin/mescroll/js/mescroll.min.js"></script>

<script>
  let meScroll
  let pm = {
    lastDttm: DateUtils.getNowInt(),
    pageNum: 1,
    pageSize: 10,
    keyWord: '',
  }

  function initPage(params) {
    //状态栏自适应
    Utils.sbhAdaptive()

    pm.keyWord = decodeURIComponent(params.key)

    jsBridge.callBridge('setTitle', {title: params.title})
    $('.center-bar').html(params.title)

    //下拉刷新、滚动加载
    meScroll = Template.createMeScroll({
      id: 'mescroll', //区域ID
      pageNum: pm.pageNum,
      downCallback: reLoadPage, //下拉刷新入口
      upCallback: goSearch //滚动加载入口
    })

  }

  function reLoadPage() {
    pm.pageNum = 1
    pm.lastDttm = DateUtils.getNowInt()

    goSearch()
  }

  //搜索入口
  function goSearch(page) {
    if (page && page.num) {
      pm.pageNum = page.num
      pm.pageSize = page.size
    }
    getInfoListForVoide()
  }

  //搜索视频列表
  function getInfoListForVoide() {
    Server.searchVoide.getInfoListForVoide({
      pageNum: pm.pageNum,
      pageSize: pm.pageSize,
      searchWord: pm.keyWord
    }).then(function (data) {
      let htmlStr = '', len = 0

      if (data.data) {
        len = data.data.length
        data.data.forEach(function (item) {
          let jsonStr = JSON.stringify({
            infoId: item.trainingId,
            infoType: '2',
            resourceType: item.trainingType
          })
          htmlStr += '<div class=\'featured-video-item flex-row\' onclick=\'goDetail(' + jsonStr + ')\'>'
          htmlStr += '<div class=\'flex-row mr15 featured-video-item-img-wrap\'>'
          htmlStr += '<div class=\'featured-video-item-img\'>'
          htmlStr += '<img src="' + item.coverImgUrl + '"/>'
          htmlStr += '</div>'
          htmlStr += '<div class=\'featured-video-item-time flex-row\'>'
          htmlStr += '<div class=\'fspx12\'>' + DateUtils.s2Str(item.videoDuration) + '</div>'
          htmlStr += '</div>'
          htmlStr += '</div>'
          htmlStr += '<div class=\'featured-video-item-content flex-column  flex-1\'>'
          htmlStr += '<div class=\'fspx15 ff500 line2\'>' + Utils.dealKeyWord(item.mainTitle, pm.keyWord) + '</div>'
          htmlStr += '<div class=\'featured-video-item-bottom flex-row justify-content-between align-items-center mtpx15 \'>'
          htmlStr += '<div class=\'fspx13 line1\' style=\'width:2rem;\'>' + Utils.dealKeyWord(item.lecturer, pm.keyWord) + '</div>'
          htmlStr += '<div>'
          htmlStr += '<span class=\'featured-video-item-icon iconfont iconbofangliang-01 mr5\'></span>'
          htmlStr += '<span class="readCnt_' + item.trainingId + '">' + Utils.dealNumber(item.readCnt) + '</span>'
          htmlStr += '</div>'
          htmlStr += '</div>'
          htmlStr += '</div>'
          htmlStr += '</div>'

        })

        if (pm.pageNum === 1) {
          $('.search-voide-list').html(htmlStr)
        } else {
          $('.search-voide-list').append(htmlStr)
        }
      }

      //下拉刷新结束回调
      meScroll.endSuccess(len, len === pm.pageSize)
    }).catch((error) => {
      meScroll.endErr()
    })

    //搜索词缓存
    if (pm.keyWord) {
      Template.searchWordCache(pm.keyWord)
    }
  }

  // 跳转原生音频详情
  function goStockDetail(infoId, infoType) {
    jsBridge.callBridge('openBrsDetail', {infoId: infoId, infoType: infoType})
  }


</script>
</html>
